<?php
/**
 * CEOfox
 *
 * @copyright  Copyright 2011-2012 CEOfox, Inc.
 * @license    http://ceofox.com/pages/license
 * @version    $Id: setting.class.php 97081 2013-05-24 09:40:17 $
 * @author     CEOfox, Inc.
 */
?>
<?php
  defined('PHPFOX') or exit('NO DICE!');
  class Follow_Component_Block_Setting extends Phpfox_Component
  {
      public function process()
      {
          Phpfox::isUser(true);
          $bIsAdmin = false;
          $oPage = Phpfox::getService('pages');
          $oFollow = Phpfox::getService('follow');
          $sType = $this->getParam('sType', 'pages');
          $aParentModule = $this->getParam('aParentModule', false);
          if(!$aParentModule)
          {
              return false;
          } 
          $bIsAjax = (PHPFOX_IS_AJAX) ? 1: false;
          
          echo '<link rel="stylesheet" type="text/css" href="'.phpFox::getParam('core.path').'module/follow/static/css/default/default/follow.css'.'"/>';
          echo '<link rel="stylesheet" type="text/css" href="'.phpFox::getParam('core.path').'module/user/static/css/default/default/privacy.css'.'"/>';
          $bHasFollowed = $oFollow->isFollow(Phpfox::getUserId(), $aParentModule['item_id'], $aParentModule['module_id']);
          
          if($aVals = $this->request()->getArray('val'))
          {
              
              if($oFollow->setFilter(Phpfox::getUserId(), $aParentModule['item_id'], $aParentModule['module_id'], $aVals))
              {
                  
                  if(isset($aVals['is_ajax']) && $aVals['is_ajax'] == false)
                  {
                    $this->url()->send('current',null, Phpfox::getPhrase('follow.update_setting_successfully'));    
                  }   
                  else
                  {
                      echo '<script type="text/javascript">tb_remove();</script>';
                  }               
              }
              else
              {
                  if(isset($aVals['is_ajax']) && $aVals['is_ajax'] == false)
                  {
                    $this->url()->send('current',null, Phpfox::getPhrase('follow.there_are_some_errors_happen_when_perform_this_action'));
                  }
                  else
                  {
                      echo '<script type="text/javascript">tb_remove();</script>';
                  }
              }
          }
          if(($aParentModule['module_id'] == 'page') && $oPage->isAdmin($aParentModule['item_id']))
          {
              $bIsAdmin = true;
          }
          $aFilter = $oFollow->getFilter(Phpfox::getUserId(), $aParentModule['item_id'], $aParentModule['module_id']);
          
          $this->template()->assign(array(
            'aFilter' => $aFilter,
            'bIsAjax' =>$bIsAjax,
            'bIsAdmin' => $bIsAdmin,
            'sType' => $sType,
            'bHasFollowed' => $bHasFollowed,
            'aParentModule' => $aParentModule,
          ));
      }
  }
   
?>

